// pages/newBuildinghouse/newAlbum/newAlbum.js
import util from "../../../utils/util.js";
import api from "../../../common/api.js";
var app = getApp();
var bannerList = [];
var bigList = [];
var currentPage = 1;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    title: ['特色', '楼盘', '沙盘', '户型', '周边配套', '售楼处', '售楼处', '售楼处', '售楼处'],
    // title: ['A', 'B', 'C', 'D', 'E'],
    num: 0,
    toView: '',
    url:[]
  },
  click(e){
    let that = this;
    currentPage = 1;
    bannerList=[];
    bigList=[];
    console.log(e)
    var num = e.currentTarget.dataset.num;
    // console.log(id)
    that.setData({
      num: e.target.dataset.num,
      refDetailCode: e.target.dataset.id,
    })
    that.getResblockImgList(e.target.dataset.id)
  },
  previewBannerImage(e){
    console.log(e)
    let that = this;
    var url = that.data.url;
    var bigurl = that.data.bigurl;
    var index = e.currentTarget.dataset.num;
    // var current = url[e.currentTarget.dataset.num];
    wx.previewImage({
      current: bigurl[index],
      urls: bigurl,
    })
  },
  // 获取具体类目的图片
  getResblockImgList(type){
      // api.getResblockImgList({
      //   hdResblockId: this.data.houdelid,
      //   userId: "f373ce5cafb449fbae8f525fd1b71a47",
      //   type: type,
      //   parentType: 'newHouseAlbum',
      // }, res => {
      //   console.log(res)
      //   var bannerList = [];
      //   res.data.content.forEach(item => bannerList.push(item.url));
      //   this.setData({
      //     url: bannerList
      //   })
      // })
    var userId = getApp().globalData.loginUserInfo.data.content.sessionUser.id,
    source = this.data.source;
    api.getResblockImgList({
      "currentPage": currentPage,
      "pageSize": 30,
      "t": {
        "hdResblockId": this.data.houdelid,
        "userId": userId,
        source,
        "parentType": "newHouseAlbum",
        "type": type
      }
    },(res)=>{
      if (res.data.content.pages.length > 0) {
        // res.data.content.pages.forEach(item => bannerList.push(item.url));
        let pages = res.data.content.pages;
        pages.forEach(item => bannerList.push(item.url));
        pages.forEach(item => bigList.push(item.bigurl));
      }
      this.setData({
        url: bannerList,
        type: type,
        bigurl: bigList,
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    api.queryPmReferenceDetailInfo({
      houseResblockId: options.hdResblockId,
    },res=>{
      let content = res.data.content;
      that.setData({
        content: content,
        houdelid: options.hdResblockId,
        source: options.source,
      })
      that.getResblockImgList(content[0].refDetailCode);
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    bannerList=[];
    bigList=[];
    currentPage = 1;
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    currentPage += 1;
    this.getResblockImgList(this.data.type)
  },

})